*****************************************************************************************************************************************************
*REPLICATION MATERIAL FOR
*Rudolph, L., & Gomm, S.
*How Does an Economic Shock Affect Environmental Attitudes, Preferences and Issue Importance? Evidence from Switzerland
*Forthcoming in Climatic Change
*
*Version 1.0, by Lukas Rudolph
*2024-02-28
*****************************************************************************************************************************************************

*****************************************************************************************************************************************************
/* DATASET
data_w1w4w6w7_replication.dta 
-- Dataset contains wave 1, wave 4, wave 6 and wave 7 Swiss Environmental Panel data, reduced to the variables of interest for this article, party recoded and labeled
-- Data source: Swiss Environmental Panel, see https://www.swissubase.ch/en/catalogue/studies/13913/17169/datasets/1220/2133/overview
*/
*****************************************************************************************************************************************************


*****************************************************************************************************************************************************
* OUTPUT 
* Evidence from panel-data regressions of environmental concern, policy preferences and vote intentions on Covid-induced economic shock and supporing material
*****************************************************************************************************************************************************

*****************************************************************************************************************************************************
*PREPARE STATA

version 16
set more off
clear all
capture log close

/* if not already installed: install the following Stata packages in order to run this do-file:
findit estout  // by Ben Jann
findit coefplot  // by Ben Jann
*/

*set working directory to folder containing the replication data set and subfolders "tab" and "fig" 

*cd " " 

*set global macros for where to save tables and figures
global tab = "Output"
global fig = "Output"

*****************************************************************************************************************************************************

********************************************************
*load data
********************************************************

use data_w1w4w6w7_replication, clear

xtset PubId year

********************************************************
*MAIN MANUSCRIPT IMPACT REGRESSIONS
********************************************************

*****
* TABLE 2: IMPACT ON ECON PERCEPTIONS
*****

eststo clear
eststo: xtreg future_personal work_worse_placebo i.year [pweight=weight_ww_placebo]  if year <= 2019  , fe cluster(PubId)
mean future_personal if work_worse_placebo==0 & year == 2018   [pweight=weight_ww_placebo]
 estat sd
 mat sd=r(sd)
 mat mean=r(mean)
estadd scalar Control_mean = mean[1,1] : est1
estadd scalar Control_sd = sd[1,1] : est1
estadd local Fixed_effects = "Yes" : est1

eststo: xtreg econ_personal work_worse  i.year [pweight=weight_ww] if year >= 2019 & year != 2021 , fe // 
mean future_personal if work_worse_placebo==0 & year == 2020 [pweight=weight_ww]
 estat sd
 mat sd=r(sd)
 mat mean=r(mean)
estadd scalar Control_mean = mean[1,1] : est2
estadd scalar Control_sd = sd[1,1] : est2
estadd local  Fixed_effects = "Yes" : est2

eststo: xtreg econ_personal work_worse  i.year [pweight=weight_ww] if year >= 2019 & year != 2020   , fe
mean future_personal if work_worse_placebo==0 & year == 2020 [pweight=weight_ww]
 estat sd
 mat sd=r(sd)
 mat mean=r(mean)
estadd scalar Control_mean = mean[1,1] : est3
estadd scalar Control_sd = sd[1,1] : est3
estadd local Fixed_effects = "Yes" : est3

estadd local EB_weights = "Yes" : est1 est2 est3

esttab   ///   using "$tab\Table2.tex" ///
, nonote order(*worse* *year*) se replace label  star(+ 0.1 * 0.05 ** 0.01) noomitted nobase stats(Fixed_effects EB_weights N N_clust Control_mean Control_sd, fmt(0 0 0 0 2 2) ) rename(work_worse_placebo work_worse 2019.year 2020.year 2021.year 2020.year) varlabels(2020.year Year) ///
mgroups("Placebo (2019-2019)" "Short term (2019-2020)" "Medium term (2019-2021)", pattern(1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span) 

	
*****
* TABLE 3: IMPACT ON ENVIRONMENTAL CONCERN OVERALL AND SUBGROUPS
*****

eststo clear
foreach x in envconcern {
qui eststo: xtreg `x' work_worse  i.year [pweight=weight_ww] if year >= 2019 & year != 2020 , fe
}

foreach y in 0 1 {
foreach x in   envconcern {
qui eststo: xtreg `x' work_worse  i.year [pweight=weight_ww_income`y'] if year >= 2019 & year != 2020 & lowincome2019 == `y', fe
}
}

foreach y in 0 1 {
foreach x in  envconcern {
qui eststo: xtreg `x' work_worse  i.year [pweight=weight_ww_concern`y'] if year >= 2019 & year != 2020 & lowconcern2019 == `y', fe
}
}

estadd local Fixed_effects = "Yes" : est1 est2 est3 est4 est5
estadd local EB_weights = "Yes" : est1 est2 est3 est4 est5


esttab    ///  using "$tab\Table3.tex" ///
, replace label se star(+ 0.1 * 0.05 ** 0.01) noomitted nobase stats(Fixed_effects EB_weights N N_clust ) ///
mgroups("All respondents" "High income" "Low income" "High env. concern" "Low env. concern", pattern(1 1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span) 


*****
* TABLE 4: IMPACT ON STATED POLICY PREFERENCES AND VOTE INTENTIONS
*****

eststo clear
foreach x in  smartvote greenpid {
qui eststo: xtreg `x' work_worse  i.year [pweight=weight_ww] if year >= 2019 & year != 2021 , fe
}
foreach x in protectovjobs energy greenvote greenpid   {
qui eststo: xtreg `x' work_worse  i.year [pweight=weight_ww] if year >= 2019 & year != 2020 , fe
}

estadd local Fixed_effects = "Yes" : est1 est2 est3 est4 est5 est6
estadd local EB_weights = "Yes" : est1 est2 est3 est4 est5 est6


esttab       using "$tab\Table4.tex" ///
, replace label  se   star(+ 0.1 * 0.05 ** 0.01)  noomitted nobase stats(Fixed_effects EB_weights N N_clust)  rename(_cons Constant 2021.year 2020.year) varlabels(2020.year Year)  ///
mgroups("Short term (2019-2020)" "Medium term (2019-2021)", pattern(1 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span) 


********************************************************
*APPENDIX DESCRIPTIVES AND BALANCE
********************************************************

***************
* Table A.3 -- Descriptives
***************

*gen labels 

gen education = w4_q4
gen popdensity = agglo
gen region = w4_bigreg 
gen gender = w6_q2
gen language = w6_lang
gen psychdistress = GHQ_dummy
label variable psychdistress "Psychological distress"

#delimit ;
label define education
1 "None"
2 "Obligatory schooling"
3 "Apprenticeship/vocational/commercial"
4 "Matura"
5 "Higher technical/vocational"
6 "University (Applied)"
7 "University, ETH"
8 "Other" ; 
#delimit cr
label values education education

#delimit ;
label define popdensity
1 "Urban, large"
2 "Urban, mid-sized"
3 "Urban, periphery"
4 "Periurban, high density"
5 "Periurban, medium density"
6 "Periurban, low density"
7 "Rural, center"
8 "Rural, mid-sized"
9 "Rural, periphery" ; 
#delimit cr
label values popdensity popdensity

label define yesno 0 "no" 1 "yes", replace

label define employment 0 "no" 1 "yes, part-time" 2 "yes, full time"

label values self_employed employment
label values employed employment
label values pensioner yesno
label values swissnational yesno
label values psychdistress yesno
label values gender gender
label values language lang
label values region bigreg

label define year 2018 "2018" 2019 "2019" 2020 "2020" 2021 "2021"
label values year year

gen maintreat = work_worse
label variable maintreat "Corona shock (main treatment indicator)"

gen coronashock_types = work_worse_cat 
label variable coronashock_types "Corona shock (affectedness types)"
#delimit ;
label define coronashock_types
0 "unaffected"
1 "job loss"
2 "income loss"
3 "fear"
4 "network"
 ; 
#delimit cr
label values coronashock_types coronashock_types

*gen binary indicators for categorical variable expressions
foreach x in popdensity region education self_employed employed pensioner gender agecat swissnational language psychdistress coronashock_types {
tab `x', gen(`x'_cat_tab) 
}

tab year, gen(yeartab)

*create table
eststo clear

eststo: estpost tabstat maintreat coronashock_types_cat_tab? yeartab? ///
future_personal econ_personal envconcern protectovjobs smartvote energy greenvote greenpid    /// 
,  columns(statistics)  /// 
statistics(mean sd min max n)  

esttab .    using  "$tab/TableA3.tex"  ///
, cells("mean(fmt(a2)) sd min max count") stats(N) label unstack replace ///
nonumbers  


***************
* Table A.4 -- Balance
***************
*Balance
label variable gender_cat_tab1 "female"

global balance = " popdensity_cat_tab* region_cat_tab* education_cat_tab* self_employed_cat_tab* employed_cat_tab* pensioner_cat_tab* gender_cat_tab1 agecat_cat_tab* swissnational language_cat_tab* psychdistress "

eststo clear
eststo : estpost ttest $balance if year == 2020, by(work_worse)

esttab  ///
	   using "$tab/TableA4.tex" ///
	, mtitles() replace  compress star(* 0.10 ** 0.05 *** 0.01)  label ///
	cells("mu_1(fmt(%12.2f) label(C)) mu_2(fmt(%12.2f) label(T)) b(fmt(%12.2f) star label(Diff-In-Means)) N_1(fmt(%12.0f) label(N C)) N_2(fmt(%12.0f) label(N T))" "mean mean se(par fmt(2))" ". . .")


********************************************************
*APPENDIX SUPPLEMENTARY ANALYSES
********************************************************

*****
* Table A.5 -- PLACEBO REGRESSIONS ON STATED POLICY PREFERENCES / VOTE INTENTIONS
*****

eststo clear
foreach x in envconcern protectovjobs energy greenvote greenpid {
qui eststo: xtreg `x' i.work_worse_placebo i.year [pweight=weight_ww_placebo]  if year <= 2019  , fe cluster(PubId)
}
esttab   using "$tab\TableA5.tex" ///
, order(*worse* *year*) replace label se star(+ 0.1 * 0.05 ** 0.01) noomitted nobase stats(N N_clust)  



*****
* Table A.6 -- Perceptions of the state of the economy
*****
label variable econ_swiss "Current Swiss econ. conditions" 
label variable future_swiss "Future Swiss econ. conditions"
eststo clear

eststo: xtreg econ_swiss i.work_worse  i.year [pweight=weight_ww] if year >= 2019 & year != 2021 , fe // & F.weight_ww_placebo!=.
mean econ_swiss if work_worse_placebo==0 & year == 2019 [pweight=weight_ww]
 estat sd
 mat sd=r(sd)
 mat mean=r(mean)
estadd scalar Control_mean = mean[1,1] : est1
estadd scalar Control_sd = sd[1,1] : est1
estadd local  EB_weights = "Yes" : est1

eststo: xtreg econ_swiss i.work_worse  i.year [pweight=weight_ww] if year >= 2019 & year != 2020   , fe
mean econ_swiss if work_worse_placebo==0 & year == 2019 [pweight=weight_ww]
 estat sd
 mat sd=r(sd)
 mat mean=r(mean)
estadd scalar Control_mean = mean[1,1] : est2
estadd scalar Control_sd = sd[1,1] : est2
estadd local EB_weights = "Yes" : est2

eststo: xtreg future_personal i.work_worse  i.year [pweight=weight_ww] if year >= 2019 & year != 2021 , fe // & F.weight_ww_placebo!=.
mean future_personal if work_worse_placebo==0 & year == 2019 [pweight=weight_ww]
 estat sd
 mat sd=r(sd)
 mat mean=r(mean)
estadd scalar Control_mean = mean[1,1] : est3
estadd scalar Control_sd = sd[1,1] : est3
estadd local  EB_weights = "Yes" : est3

eststo: xtreg future_personal i.work_worse  i.year [pweight=weight_ww] if year >= 2019 & year != 2020   , fe
mean future_personal if work_worse_placebo==0 & year == 2019 [pweight=weight_ww]
 estat sd
 mat sd=r(sd)
 mat mean=r(mean)
estadd scalar Control_mean = mean[1,1] : est4
estadd scalar Control_sd = sd[1,1] : est4
estadd local EB_weights = "Yes" : est4

eststo: xtreg future_swiss i.work_worse  i.year [pweight=weight_ww] if year >= 2019 & year != 2021 , fe // & F.weight_ww_placebo!=.
mean future_swiss if work_worse_placebo==0 & year == 2019 [pweight=weight_ww]
 estat sd
 mat sd=r(sd)
 mat mean=r(mean)
estadd scalar Control_mean = mean[1,1] : est5
estadd scalar Control_sd = sd[1,1] : est5
estadd local  EB_weights = "Yes" : est5

eststo: xtreg future_swiss i.work_worse  i.year [pweight=weight_ww] if year >= 2019 & year != 2020   , fe
mean future_swiss if work_worse_placebo==0 & year == 2019 [pweight=weight_ww]
 estat sd
 mat sd=r(sd)
 mat mean=r(mean)
estadd scalar Control_mean = mean[1,1] : est6
estadd scalar Control_sd = sd[1,1] : est6
estadd local EB_weights = "Yes" : est6

esttab        using "$tab\TableA6.tex" ///
, nonote order(*worse* *year*) replace label se star(+ 0.1 * 0.05 ** 0.01) noomitted nobase stats(EB_weights N N_clust Control_mean Control_sd, fmt(0 0 0 2 2) )



*****
* Table A.7 -- INTERACTION MODELS
*****

foreach x in envconcern energy greenvote greenpid { //  
gen `x'_diff = `x'  - L2.`x'
}
label variable envconcern_diff "2021-2019 env. conc. ind."
label variable energy_diff "2021-2019 energy ind."
label variable greenvote_diff "2021-2019 green cand. ind."
label variable greenpid_diff "2021-2019 green vote int."

eststo clear
foreach x in energy greenvote greenpid { 
eststo: reg `x'_diff c.envconcern_diff##i.work_worse  [pweight=weight_ww] , r // i.(w4_q4 w6_q2 w6_lang w4_bigreg )
}
esttab     using "$tab\TableA7.tex" ///
, nonote replace label se star(+ 0.1 * 0.05 ** 0.01) noomitted nobase stats(N  ) 


 
*****
* Table A.8 -- alternative coding of treatment -- job loss as treatment
*****

eststo clear
foreach x in econ_personal smartvote greenpid {
qui eststo: xtreg `x' i.work_worse_cat  i.year [pweight=weight_job] if year >= 2019 & year != 2021 , fe
}
foreach x in econ_personal envconcern protectovjobs energy greenvote greenpid {
qui eststo: xtreg `x' i.work_worse_cat  i.year [pweight=weight_job] if year >= 2019 & year != 2020 , fe
}

esttab   using "$tab\TableA8.tex" ///
, replace label se star(+ 0.1 * 0.05 ** 0.01) noomitted nobase stats(N N_clust) ///
mgroups("Short term (2019-2020)" "Medium term (2019-2021)", pattern(1 0 0 1 0 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span) 


*****
* Table A.9 -- alternative coding of treatment -- income loss as treatment
*****

eststo clear
foreach x in econ_personal smartvote greenpid {
qui eststo: xtreg `x' i.work_worse_cat  i.year [pweight=weight_inc] if year >= 2019 & year != 2021 , fe
}
foreach x in econ_personal envconcern protectovjobs energy greenvote greenpid {
qui eststo: xtreg `x' i.work_worse_cat  i.year [pweight=weight_inc] if year >= 2019 & year != 2020 , fe
}

esttab   using "$tab\TableA9.tex" ///
, replace label se star(+ 0.1 * 0.05 ** 0.01) noomitted nobase stats(N N_clust) ///
mgroups("Short term (2019-2020)" "Medium term (2019-2021)", pattern(1 0 0 1 0 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span) 

*****
* Table A.10 -- alternative coding of treatment -- fear of job loss as treatment
*****
eststo clear
foreach x in econ_personal smartvote greenpid {
qui eststo: xtreg `x' i.work_worse_cat  i.year [pweight=weight_fear] if year >= 2019 & year != 2021 , fe
}
foreach x in econ_personal envconcern protectovjobs energy greenvote greenpid {
qui eststo: xtreg `x' i.work_worse_cat  i.year [pweight=weight_fear] if year >= 2019 & year != 2020 , fe
}

esttab   using "$tab\TableA10.tex" ///
, replace label se star(+ 0.1 * 0.05 ** 0.01) noomitted nobase stats(N N_clust) ///
mgroups("Short term (2019-2020)" "Medium term (2019-2021)", pattern(1 0 0 1 0 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span) 

*****
* Table A.11 -- alternative coding of treatment -- job loss in personal network as treatment
*****

eststo clear
foreach x in econ_personal smartvote greenpid {
qui eststo: xtreg `x' i.work_worse_cat  i.year [pweight=weight_network] if year >= 2019 & year != 2021 , fe
}
foreach x in econ_personal envconcern protectovjobs energy greenvote greenpid {
qui eststo: xtreg `x' i.work_worse_cat  i.year [pweight=weight_network] if year >= 2019 & year != 2020 , fe
}

esttab    using "$tab\TableA11.tex" ///
, replace label se star(+ 0.1 * 0.05 ** 0.01) noomitted nobase stats(N N_clust) ///
mgroups("Short term (2019-2020)" "Medium term (2019-2021)", pattern(1 0 0 1 0 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span) 



